package com.nifostasky.config.fallback;

import com.nifostasky.config.StudentFeignClientTwo;
import com.nifostasky.entity.Student;
import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;

/**
 * fallbackFactory方式
 */
@Component
public class FallbackFactoryFeign implements FallbackFactory<StudentFeignClientTwo> {
    @Override
    public StudentFeignClientTwo create(Throwable throwable) {
        return new StudentFeignClientTwo() {
            /**
             * queryUserById4000ms()方法 , 意味着这是 queryUserById4000ms()方法熔断后的回调方法;
             * @return
             */
            @Override
            public Student queryUserById(Integer id) {
                System.out.println("==============熔断了,fallbackFactory方式;====================");
                //输出异常信息;
                System.out.println(throwable.getMessage());
                return new Student();
            }
        };
    }
}
